package com.hspedu.newData.dmsxl.链表.快慢指针;

import com.hspedu.newData.dmsxl.ds.ListNode;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-06 
 * @Version: 1.0
 */

public class LC328奇偶链表 {

    // todo
    public ListNode oddEvenList(ListNode head) {

        if (head == null || head.next == null) return head;

        ListNode firstNode = head;
        ListNode secondNode = head.next;
        ListNode temp = head.next;

        while (secondNode != null && secondNode.next != null){
            firstNode.next = secondNode.next;
            secondNode.next = secondNode.next.next;
            firstNode = firstNode.next;
            secondNode = secondNode.next;
        }

        firstNode.next = temp;
        return head;
    }

}
